package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import entity.Stuinfo;



public class StuinfoDao {

	private static String driver = "com.mysql.jdbc.Driver";
	private static String url = "jdbc:mysql://localhost:3306/servlet";
	private static String username = "root";
	private static String password = "root";
	private static Connection conn;

    
    private static Connection getConnection(){
		
    	try {
			Class.forName(driver);
			conn=DriverManager.getConnection(url, username, password);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    	
    	
    	return conn;
    }
  
  
    /*
     * 获得学生表
     */
    
     public List<Stuinfo> getStuinfo(){
		List<Stuinfo> list=new ArrayList<Stuinfo>();
    	 getConnection();
    	 String sql="SELECT * FROM s_info";
    	 
    	 
    	 try {
			PreparedStatement preparedStatement=conn.prepareStatement(sql);
			ResultSet resultSet=preparedStatement.executeQuery();
			
			while(resultSet.next()){
				Stuinfo stuinfo=new Stuinfo();
				stuinfo.setId(resultSet.getString("id"));
				stuinfo.setId(resultSet.getString("name"));
				stuinfo.setId(resultSet.getString("age"));
				stuinfo.setId(resultSet.getString("sex"));
				stuinfo.setId(resultSet.getString("math"));
				list.add(stuinfo);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	 
    	 return list;
    	 
     }
     
}
